package cn.ffcs.bpmpvc.services.impl;

import java.util.List;

import cn.ffcs.bpm.model.ProcTranRecord;
import cn.ffcs.bpmpvc.dao.AppBusinessReqDao;
import cn.ffcs.bpmpvc.dao.PocReqPlanDao;
import cn.ffcs.bpmpvc.model.PocReqPlan;
import cn.ffcs.bpmpvc.services.PocReqPlanService;
import cn.ffcs.bpmpvc.svc.ProcessPvcService;
import cn.ffcs.bpmpvc.svc.TaskAssignBean;
import cn.ffcs.bpmpvc.svc.TaskService;
import cn.ffcs.bpmpvc.web.views.ProcessInstView;
import cn.ffcs.businessrequest.model.BusinessRequest;
import cn.ffcs.organ.model.Person;

public class PocReqPlanServiceImpl implements PocReqPlanService {
	private ProcessPvcService processPvcService;
	private TaskService taskService;
	private PocReqPlanDao pocReqPlanDao;
	private AppBusinessReqDao appBusinessReqDao;
	public ProcTranRecord saveReqPlanStartFlow(String processConfigId,Person person,List<TaskAssignBean> nextTasksList,boolean isCommit,PocReqPlan pocReqPlan){
        //启动流程
        ProcessInstView processInstView=getProcessPvcService().startProcessInst(processConfigId,person,nextTasksList,isCommit);
        pocReqPlan.setProcinstId(processInstView.getProcessStatus().getProcinstId());
        getPocReqPlanDao().save(pocReqPlan);
        return processInstView.getProcTranRecord();
    }
	
	
	public void saveDataAndCommitTask(String flowTaskId, String content,PocReqPlan pocReqPlan, List<TaskAssignBean> nextTasksList,boolean isCommit) {
		// TODO Auto-generated method stub
		//保存
        ProcTranRecord procTranRecord=null;
        if(isCommit){
            procTranRecord=getTaskService().completeTask(flowTaskId, content, nextTasksList);
        }else{
            procTranRecord=getTaskService().saveTaskAssignUser(flowTaskId, content, nextTasksList);
        }
        if("01".equals(pocReqPlan.getConfirmType())){
        	//更新需求单的完成时间
        	BusinessRequest businessRequest=getAppBusinessReqDao().getBusinessRequestById(Integer.valueOf(pocReqPlan.getReqId()));
        	//businessRequest.setAdvanTime(pocReqPlan.getDelayTime());
        	businessRequest.setPlanTime(pocReqPlan.getDelayTime());
        	getAppBusinessReqDao().save(businessRequest);
        }
        getPocReqPlanDao().save(pocReqPlan);
	}
	public ProcessPvcService getProcessPvcService() {
		return processPvcService;
	}
	public void setProcessPvcService(ProcessPvcService processPvcService) {
		this.processPvcService = processPvcService;
	}
	public TaskService getTaskService() {
		return taskService;
	}
	public void setTaskService(TaskService taskService) {
		this.taskService = taskService;
	}

	public PocReqPlanDao getPocReqPlanDao() {
		return pocReqPlanDao;
	}

	public void setPocReqPlanDao(PocReqPlanDao pocReqPlanDao) {
		this.pocReqPlanDao = pocReqPlanDao;
	}


	public AppBusinessReqDao getAppBusinessReqDao() {
		return appBusinessReqDao;
	}


	public void setAppBusinessReqDao(AppBusinessReqDao appBusinessReqDao) {
		this.appBusinessReqDao = appBusinessReqDao;
	}

	
	 
}
